package com.ktgj.other.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.EtDimArea;
import com.ktgj.other.service.IEtDimAreaService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/area")
public class EtDimAreaController extends BaseController
{
    @Autowired
    private IEtDimAreaService etDimAreaService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "other:area:list")
    @GetMapping("/list")
    public TableDataInfo list(EtDimArea etDimArea)
    {
        startPage();
        List<EtDimArea> list = etDimAreaService.selectEtDimAreaList(etDimArea);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "other:area:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EtDimArea etDimArea) throws IOException
    {
        List<EtDimArea> list = etDimAreaService.selectEtDimAreaList(etDimArea);
        ExcelUtil<EtDimArea> util = new ExcelUtil<EtDimArea>(EtDimArea.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "other:area:query")
    @GetMapping(value = "/{areaid}")
    public AjaxResult getInfo(@PathVariable("areaid") Long areaid)
    {
        return AjaxResult.success(etDimAreaService.selectEtDimAreaById(areaid));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "other:area:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EtDimArea etDimArea)
    {
        return toAjax(etDimAreaService.insertEtDimArea(etDimArea));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "other:area:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EtDimArea etDimArea)
    {
        return toAjax(etDimAreaService.updateEtDimArea(etDimArea));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "other:area:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaids}")
    public AjaxResult remove(@PathVariable Long[] areaids)
    {
        return toAjax(etDimAreaService.deleteEtDimAreaByIds(areaids));
    }

    /**
     * 城市列表
     * */
    @PostMapping("/city")
    public AjaxResult city(@RequestBody Map<String, Object> map){
        String name = null;
        if (map.get("name") != null && !map.get("name").equals("")){
            name = map.get("name").toString();
        }

        List<EtDimArea> etDimAreaList = etDimAreaService.city(name);
        return AjaxResult.success(etDimAreaList);
    }
}
